<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<script type="text/javascript">
    $(function() {

        $('#admin_experience_datagrid').datagrid({
            url : '${pageContext.request.contextPath}/memberController/datagrid.action?memberType=t',
            fit : true,
            fitColumns : true,
            border : false,
            pagination : true,
            idField : 'id',
            pageSize : 10,
            pageList : [ 10, 20, 30, 40, 50 ],
            sortName : 'createTime',
            sortOrder : 'desc',
            checkOnSelect : false,
            selectOnCheck : false,
            nowrap : false,
            frozenColumns : [ [ {
                field : 'id', title : '编号', checkbox : true}, {
                field : 'cardId', title : '卡号', sortable : true} ] ],
            columns : [ [ {
                field : 'name', title : '姓名', sortable : true}, {
                field : 'createTime', title : '创建时间', sortable : true}, {
                field : 'mobile', title : '手机号', sortable : true}, {
                field : 'email', title : '电子邮箱', sortable : true}, {
                field : 'statusName', title : '状态', sortable : true}, {
                field : 'memberTypeName', title : '会员类型', sortable : true}, {
                field : 'cid', title : '身份证号', sortable : true}, {
                field : 'genderName', title : '性别', sortable : true}, {
                field : 'payTypeName', title : '支付方式', sortable : true}, {
                field : 'regCharge', title : '缴费金额（元）', sortable : true, align : 'right'}, {
                field : 'memberFee', title : '会费（元）', sortable : true, align : 'right'}, {
                field : 'balance', title : '消费余额（元）', sortable : true, align : 'right'}, {
                field : 'jifen', title : '积分', sortable : true, align : 'right'}, {
                field : 'action1', title : '查看详情/修改', align : 'center', formatter : function(value, row, index) {
                    return formatString('<img onclick="admin_experience_editFun(\'{0}\');" src="{1}"/ title="查看详情/修改">', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/pencil.png');
                }
                }]],
            toolbar : [ {
                text : '添加会员', iconCls : 'icon-add', handler : function() {
                    admin_experience_appendFun();
                }
            }]
        });
    });

    function admin_experience_searchFun() {
        $('#admin_experience_datagrid').datagrid('load', serializeObject($('#admin_experience_searchForm')));
    }

    function admin_experience_cleanFun() {
        $('#admin_member_searchForm input').val('');
        $('#admin_experience_datagrid').datagrid('load', {});
    }

    function admin_experience_editFun(id) {
        $('#admin_experience_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $('<div/>').dialog({
            href : '${pageContext.request.contextPath}/admin/member_edit.jsp',
            width : 600,
            height : 500,
            modal : true,
            title : '修改会员信息',
            buttons : [ {
                text : '保存',
                iconCls : 'icon-edit',
                handler : function() {
                    var d = $(this).closest('.window-body');
                    $('#admin_memberEdit_editForm').form('submit', {
                        url : '${pageContext.request.contextPath}/memberController/edit.action',
                        success : function(result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.success) {
                                    $('#admin_experience_datagrid').datagrid('reload');
                                    d.dialog('destroy');
                                }
                                $.messager.show({
                                    title : '提示',
                                    msg : r.msg
                                });
                            } catch (e) {
                                $.messager.alert('提示', result);
                            }
                        }
                    });
                }
            } ],
            onClose : function() {
                $(this).dialog('destroy');
            },
            onLoad : function() {
                var index = $('#admin_experience_datagrid').datagrid('getRowIndex', id);
                var rows = $('#admin_experience_datagrid').datagrid('getRows');
                var o = rows[index];
                $('#admin_memberEdit_editForm').form('load', o);
            }
        });
    }

    function admin_experience_appendFun() {
        $('#admin_experience_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $('<div/>').dialog({
            href : '${pageContext.request.contextPath}/admin/member_add.jsp?type=0',
            width : 600,
            height : 500,
            modal : true,
            title : '添加会员',
            buttons : [ {
                text : '保存',
                iconCls : 'icon-add',
                handler : function() {
                    var d = $(this).closest('.window-body');
                    $('#admin_memberAdd_addForm').form('submit', {
                        url : '${pageContext.request.contextPath}/memberController/add.action',
                        success : function(result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.success) {
                                    $('#admin_experience_datagrid').datagrid('load',{sort : 'createTime', order : 'desc'});
                                    d.dialog('destroy');
                                }
                                $.messager.show({
                                    title : '提示',
                                    msg : r.msg
                                });
                            } catch (e) {
                                $.messager.alert('提示', result);
                            }
                        }
                    });
                }
            } ],
            onClose : function() {
                $(this).dialog('destroy');
            }
        });
    }
</script>
<div class="easyui-layout" data-options="fit : true,border : false">
    <div data-options="region:'north',title:'查询条件',border:false" style="height:200px" align="center">
        <form id="admin_experience_searchForm">
            <table class="tableForm">
                <tr>
                    <th style="width: 170px;">卡号(可模糊查询)</th>
                    <td><input name="cardId" style="width: 315px;" /></td>
                </tr>
                <tr>
                    <th style="width: 170px;">姓名(可模糊查询)</th>
                    <td><input name="name" style="width: 315px;" /></td>
                </tr>
                <tr>
                    <th style="width: 170px;">手机号(可模糊查询)</th>
                    <td><input name="mobile" style="width: 315px;" /></td>
                </tr>
                <tr>
                    <th>创建时间</th>
                    <td><input name="createTimeStart" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" />至<input name="createTimeEnd" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" /></td>
                </tr>
            </table>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="admin_experience_searchFun();">过滤</a> <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="admin_experience_cleanFun();">取消过滤</a>
        </form>
    </div>
    <div data-options="region:'center',border:false">
        <table id="admin_experience_datagrid"></table>
    </div>
</div>